package cpr.command;

import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import cpr.DefaultCommandHandler;
import cpr.Printer;
import cpr.Rule;
import cpr.Utils;
import cpr.data.HLVector;
import cpr.data.SplitCluster;
import cpr.data.SplitClusterComparator;

public class CmdSplitBy extends DefaultCommandHandler {

	public CmdSplitBy() {
		super("splitby");
		setQuickInfo("Split root or previously found parent cluster into a new cluster set according to a given score. Usage: splitby SCORE [PARENT_CLUSTER]");
	}


	
	public void execute(String[] params) throws Exception {
		SplitCluster parentCluster = null;
		int IMAGE_SCORE = getCommandContext().getContext().getScoreHelper().convertStringToScore(getParameter(params, 1));
		int parent_cluster = Integer.parseInt(getParameter(params, 2,"0"))-1;
		if (parent_cluster!=-1) {
			parentCluster = getCommandContext().getClusterItem(getCommandContext().getContext().getCurrentWorksetContext().getClusterSet(), parent_cluster);
		}
        HLVector vector = new HLVector(IMAGE_SCORE);

        Set set = getCommandContext().getContext().getSelectContext().selectSplitClusterSet(vector,parentCluster);
        Printer.println(""+set.size()+" clusters");
        
        getCommandContext().getContext().getCurrentWorksetContext().setClusterSet(set);
        getCommandContext().executeInCurrentThread("print");
    }
	
	
}
